var planItemDetails = {
	getData : function() {
		var planId = getUrlParam("planId");
		if (checkValue4(planId)) {
			$.ajax({
				dataType : "json",
				type : "post",
				data : "planId=" + planId,
				async : false,
				url : "/app/plan!getProjectListByPlanId",
				success : function(data) {
					backUrl.addCookie(data.state);
					if (data.state == "success") {
						planItemDetails.createContent(data.msg);
					} else if (data.state == "error") {
						errorAlert(data.msg);
					}
				}
			});
		} else {
			errorAlert("无法获取数据！");
		}
	},
	createContent : function(data) {
		var pm = $("#dataShow");
		var content = "";
		pm.empty();
		if (data != null && data.length != 0) {
			$("#pageShow").show();
			content = "<tr id='titleTr'>" + "<th width='30%' scope='col'>项目名称</th>"
					+ "<th width='10%' scope='col'>实施时间</th>" + "<th width='10%' scope='col'>总投资（亿）</th>"
					+ "<th width='15%' scope='col'>主管部门</th>" + "<th width='25%' scope='col'>资金来源</th>"
					+ "<th width='10%' scope='col'>操作</th></tr>";
			for ( var int = 0; int < data.length; int++) {
				var v = data[int];
				var id = v.id;
				var name = v.name;
				var fund = v.fund;
				var impl = v.impl_time;
				var fundPlan = v.fund_plan;
				var mgrDepart = v.mgr_depart;
				var ppiid = v.projectPlanItem.id;

				var _name = name;
				if (name.length > 25) {
					name = name.substring(0, 24) + "...";
				}
				var _fundPlan = fundPlan;
				if (fundPlan.length > 20) {
					fundPlan = fundPlan.substring(0, 19) + "...";
				}
				var _mgrDepart = mgrDepart;
				if (null != mgrDepart && "" != mgrDepart && mgrDepart.length > 12) {
					mgrDepart = mgrDepart.substring(0, 10) + "...";
				}
				if (null == fund || typeof (fund) == "undefined") {
					fund = "";
				}
				if (null == mgrDepart || typeof (mgrDepart) == "undefined") {
					mgrDepart = "";
				}
				content += "<tr><td align='center'><a href='/app/project!getProjectDetailedById?p_id=" + id
						+ "' target='_blank' title='" + _name + "' class='tempClass'>" + name
						+ "</a></td><td align='center'>" + impl + "</td><td align='center'>" + fund
						+ "</td><td align='center' title='" + _mgrDepart + "'>" + mgrDepart
						+ "</td><td align='center' title='" + _fundPlan + "'>" + fundPlan
						+ "</td><td align='center'><a href='javascript:deletePlanItem(" + ppiid
						+ ")'>取消计划</a></td></tr>";
			}
		} else {
			$("#pageShow").hide();
			content = "<tr id='noData'><td align='center'><h1>暂无数据</h1></td></tr>";
		}
		pm.append(content);
		planDetailsPoshytip();
	}
};
var planDetails = {
	getData : function() {
		var planId = getUrlParam("planId");
		if (checkValue4(planId)) {
			$.ajax({
				dataType : "json",
				type : "post",
				data : "planId=" + planId,
				async : false,
				url : "/app/plan!getPlanByPlanId",
				success : function(data) {
					backUrl.addCookie(data.state);
					if (data.state == "success") {
						planDetails.createContent(data.msg);
					} else if (data.state == "error") {
						errorAlert(data.msg);
					}
				}
			});
		} else {
			errorAlert("无法获取数据！");
		}
	},
	createContent : function(data) {
		var pm = $("#planDetails");
		var content = "";
		pm.empty();
		if (data != null) {
			content = "<font size='4'>" + data.name + "（" + data.countProject + "项）</font>";
		} else {
			content = "暂无数据";
		}
		pm.html(content);
	}
};
function planDetailsPoshytip() {
	$("#dataShow").find("td").poshytip({
		className : 'tip-darkgray',
		showOn : 'hover',
		alignTo : 'target',
		alignX : 'center',
		alignY : "center",
		allowTipHover : true,
		fade : true,
		slide : true
	});
	$(".tempClass").poshytip({
		className : 'tip-darkgray',
		showOn : 'hover',
		alignTo : 'target',
		alignX : 'right',
		alignY : "center",
		offsetX : 10,
		allowTipHover : true,
		fade : true,
		slide : true
	});
};
/**
 * 取消计划
 * 
 * @param id
 */
function deletePlanItem(id) {
	art.dialog.confirm('确认取消？', function() {
		$.ajax({
			dataType : "json",
			type : "post",
			data : {
				"planItemId" : id
			},
			url : "/app/plan!deleteProjectPlanItem",
			success : function(data) {
				backUrl.addCookie(data.state);
				if (data.state == "success") {
					planItemDetails.getData();
					tipsAlert(data.msg);
				} else if (data.state == "error") {
					errorAlert(data.msg);
				}
			}
		});
	});
}
function planDetailsOnload() {
	planItemDetails.getData();
	planDetails.getData();
	var planId = getUrlParam("planId");
	if (checkValue4(planId)) {
		$("#outExcel").attr("href", "/app/plan!planExcelByPlanId?planId=" + planId);
	} else {
		$("#outExcel").click(function() {
			errorAlert("不能导出，无法找到该计划！");
		});
	}
}